﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pampa.CRUD.Configuration;

namespace Pampa.MVC.Fluent.Crud.Groups
{
    public class HeaderGroupBuilder<TGroup> : GroupBuilder<TGroup, TGroup>
    {
        private readonly HeaderGroup _headerGroup;

        public HeaderGroupBuilder(EntityConfig<TGroup> entityConfig, HeaderGroup group) : base(entityConfig, group)
        {
            _headerGroup = group;
        }

        public HeaderGroupBuilder<TGroup> Id(string id)
        {
            _headerGroup.Id = id;
            return this;
        }

        public HeaderGroupBuilder<TGroup> Title(string title)
        {
            _headerGroup.Title = title;
            return this;
        }

        public HeaderGroupBuilder<TGroup> Columns(int columns)
        {
            _headerGroup.Columns = columns;
            return this;
        }

        public HeaderGroupBuilder<TGroup> AddEditPermission(Func<TGroup, bool> action)
        {
            var guid = new Guid().ToString();
            this.ParentEditor.SecurityManager.AddEditRule(guid, action);
            _headerGroup.PermissionRequired = guid;
            return this;
        }

        public HeaderGroupBuilder<TGroup> AddViewPermission(Func<TGroup, bool> action)
        {
            var guid = new Guid().ToString();
            this.ParentEditor.SecurityManager.AddViewRule(guid, action);
            _headerGroup.PermissionRequired = guid;
            return this;
        }

        public HeaderGroupBuilder<TGroup> AddCustomPermission(string permision)
        {
            _headerGroup.PermissionRequired = permision;
            return this;
        }
    }
}
